﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DataAccessLayer.Models
{
    public class ProductFactory
    {
        private static ProductFactory instance = null;

        public static ProductFactory getInstance()
        {
            if (instance == null) return new ProductFactory();
            return instance;
        }

        public List<Product> getProducts()
        {
            return CodedObjectLoader.getInstance().getProducts();
        }

        public Product getProduct(int id)
        {
            foreach (Product p in CodedObjectLoader.getInstance().getProducts())
            {
                if (p.ProductId == id) return p;
            }
            return null;
        }
    }

    public class FacilityFactory
    {
        private static FacilityFactory instance = null;

        public static FacilityFactory getInstance()
        {
            if (instance == null) return new FacilityFactory();
            return instance;
        }

        public Facility create(Product p)
        {
            if (p is HousingLoan) return new FacilityHousingLoan();
            if (p is TermLoan) return new FacilityTermLoan();
            if (p is OverDraft) return new FacilityOverDraft();

            return null;
        }
    }

    public class SecurityFactory
    {
        private static SecurityFactory instance = null;

        public static SecurityFactory getInstance()
        {
            if (instance == null) return new SecurityFactory();
            return instance;
        }

        public Security create(string code)
        {
            if (code == "LM") return new Mortgage();
            if (code == "PG") return new PersonalGuarantee();
            if (code == "FD") return new FixedDeposit();

            return null;
        }
    }
}
